﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web;

namespace BCGC.BLL.Helper
{
    public class SiteUtility
    {
        public static string FormateImage(string imageName,ImageType imageType)
        {
            string imgPath = string.Empty;
            switch((int)imageType)
            {
                case (int)ImageType.UserImage:
                    {
                        if (ValidateImage(imageName, SiteConstants.UserImagePath))
                        {
                            imgPath = SiteConstants.UserImagePath + imageName;
                        }
                        else
                        {
                            imgPath = SiteConstants.UserImagePath + SiteConstants.DefaultUserImage;
                        }
                        
                        break;
                    }
                default:
                    { imgPath = string.Empty; break; }
            }

            return imgPath;
        }
        public static bool ValidateImage(string imageName,string defaultImagePath)
        {
            bool result=true;
            if (string.IsNullOrEmpty(imageName))
                result = false;
            
            if (result)
            {
                string filePath = HttpContext.Current.Server.MapPath(defaultImagePath + imageName);
                if (!File.Exists(filePath))
                    result = false;
            }

            return result;
            
        }
    }
}
